<template>
  <div class="member-deposit-dialog">
    <el-dialog :visible.sync="dialogVisible" :before-close="handleClose" width="760px">
      <div class="title" slot="title">会员卡充值</div>
      <div class="member-deposit-content">
        <div class="content-title">持卡人信息</div>
        <div>
          <div class="content-item-title">
            <span class="s1">持卡人姓名：</span>
            <span class="s2"><el-input placeholder="请选择" disabled v-model="memberInfo.userName"/></span>
            <i @click="getMembers" class="el-icon-user-solid"></i>
          </div>
          <div class="content-item-title">
            <span class="s1">会员卡：</span>
            <span class="s2"><el-input placeholder="请选择" disabled v-model="memberInfo.cardName"/></span>
          </div>
          <div class="content-item-title">
            <span class="s1">手机号码：</span>
            <span class="s2"><el-input placeholder="请输入" disabled v-model="memberInfo.phone"/></span>
          </div>
        </div>
        <div class="content-title">充值和赠送套餐</div>
        <div class="content-item">
          <div class="item">
            <span class="s1"><span class="required">*</span>充值金额：</span>
            <span class="s2"><el-input placeholder="请输入" v-model="depositAmount" clearable/></span>
          </div>
          <div class="item">
            <span class="s1"><span class="required">*</span>支付方式：</span>
            <span class="s2">
              <el-select v-model="payType" clearable>
                <el-option value="wx" label="微信"/>
                <el-option value="alipay" label="支付宝"/>
              </el-select>
            </span>
          </div>
        </div>
        <div class="content-item">
          <div class="item">
            <div class="s1">赠送套餐：</div>
            <div class="item-details">
              <div class="detail" v-for="(item,index) in defaultComboList" :key="index">
                <span>{{ item.name }}</span>
                <span @click="removePlatter(item)" class="item-close"><i class="icon-x"></i></span>
              </div>
              <div class="modify" @click="modifyInfo=!modifyInfo">修改</div>
            </div>
          </div>
        </div>
        <div v-if="modifyInfo" class="content-table">
          <div style="width: 85%">
            <el-table :data="comboList" border>
              <el-table-column prop="name" label="名称"/>
              <el-table-column prop="expireDate" label="有效期"/>
              <el-table-column prop="num" label="项目次数"/>
              <el-table-column prop="amount" label="总金额"/>
              <el-table-column label="操作">
                <template slot-scope="item">
                  <span class="table-add" @click="addPlatter(item.row)">添加</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div class="btn">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <members-dialog ref="membersDialog" @memberPages="getMembers"
                    @selectMember="getMember" :members="membersData"/>
  </div>
</template>

<script>
import MembersDialog from '@/views/member/dialog/membersDialog'
export default {
  name: 'memberDeposit',
  components: { MembersDialog },
  data () {
    return {
      dialogVisible: false,
      modifyInfo: false,
      payType: '',
      depositAmount: '',
      memberInfo: {},
      defaultComboList: [
        { id: 1, name: '推拿套餐' }, { id: 2, name: '针灸' },
        { id: 3, name: '拔罐套餐A' }, { id: 4, name: '拔罐套餐B' }
      ],
      comboList: [],
      membersData: { data: [], count: 0 }
    }
  },
  methods: {
    removePlatter (item) {
      this.defaultComboList = this.defaultComboList.filter(i => {
        if (item.id !== i.id) {
          return i
        }
      })
    },
    addPlatter (item) {
      const isExist = this.defaultComboList.some(i => i.id === item.id)
      if (isExist) {
        this.$message({
          type: 'error',
          message: '此套餐已添加，请勿重复添加！'
        })
        return
      }
      this.defaultComboList.push({
        id: item.id,
        name: item.name
      })
    },
    getMembers (pageTerms) {
      this.membersData = { data: [], count: 0 }
      pageTerms = pageTerms || { pageNo: 1, pageSize: 5 }
      for (let i = 1; i < 7; i++) {
        this.membersData.data.push(
          { id: i, userName: '李' + i, cardName: '会员卡' + i, phone: '166666666' + i }
        )
      }
      this.membersData.count = this.membersData.data.length
      this.$refs.membersDialog.show()
    },
    getMember (member) {
      this.memberInfo = member
    },
    show (info) {
      this.memberInfo = info
      this.comboList = []
      for (let i = 1; i < 10; i++) {
        this.comboList.push(
          { id: 4 + i, name: '推拿套餐' + i, expireDate: 316 + i, num: i, amount: 300 + i }
        )
      }
      this.modifyInfo = false
      this.dialogVisible = true
    },
    handleClose () {
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped lang="scss">
@import "~@/styles/variables";
.member-deposit-dialog {
  .title {
    border-bottom: 1px solid #e5e1e1;
    padding-bottom: 10px;
    font-size: 16px;
  }
  .member-deposit-content {
    margin-top: -30px;
    .content-title {
      margin-top: 15px;
      color: rgba(0, 0, 0, 0.85);
    }
    .content-item-title{
      display: flex;
      align-items: center;
      margin: 15px 40px;
      .s1 {
        color: rgba(0, 0, 0, 0.75);
        width: 100px;
        text-align: right;
      }
      .s2{
        width: 300px;
      }
      i {
        cursor: pointer;
        margin-left: 10px;
        font-size: 20px;
        color: $mainBg;
      }
    }
    .content-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin: 20px 40px;
      .s1 {
        width: 100px;
        text-align: right;
        color: rgba(0, 0, 0, 0.75);
        .required {
          margin-right: 5px;
          color: #E23232;
        }
      }
      .item-details,.item {
        display: flex;
        align-items: center;
      }
      .item-details {
        flex-wrap: wrap;
        flex: 1;
        .detail {
          background: #E9F6FF;
          border-radius: 5px;
          padding: 5px 25px 5px 10px;
          margin: 10px 15px 0 0;
          color: #38739C;
          position: relative;
          color: #38739C;
          font-weight: 400;
          .item-close {
            position: absolute;
            top: 3px;
            right: 6px;
            font-size: 18px;
            cursor: pointer;
          }
        }
        .modify {
          margin-top: 10px;
          font-size: 14px;
          color: #0F9CFF;
          text-decoration: underline;
          cursor: pointer;
        }
      }
    }
    .content-table{
      display: flex;
      justify-content: flex-end;
      margin-top: 20px;
      .table-add{
        cursor: pointer;
        color: $mainBg;
      }
    }
  }
  .btn {
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
}
</style>
